package com.wenhuitec.productlib.ui.adapter.attr;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.gzwh.weblib.bean.NzProductAttrModel;
import com.wenhuitec.productlib.R;
import com.wenhuitec.productlib.ui.view.SelectAttrView;

import java.util.List;

public class AttrCateAdapter extends RecyclerView.Adapter<AttrCateAdapter.MyViewHolder> {
    private List<NzProductAttrModel> datas;
    private LayoutInflater inflater;
    private int checked;
    private Context mContext;

    private OnUserClick mOnUserClick;

    public void setmOnUserClick(OnUserClick mOnUserClick) {
        this.mOnUserClick = mOnUserClick;
    }

    public interface OnUserClick {
        void onClick(NzProductAttrModel productAttrModel);
    }

    public AttrCateAdapter(Context context, List<NzProductAttrModel> datas) {
        inflater = LayoutInflater.from(context);
        mContext = context;
        this.datas = datas;
    }

    //创建每一行的View 用RecyclerView.ViewHolder包装
    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View itemView = inflater.inflate(R.layout.item_attr_category, parent, false);
        return new MyViewHolder(itemView);
    }

    //给每一行View填充数据
    @Override
    public void onBindViewHolder(MyViewHolder holder, int position) {
        holder.categoryNameTv.setText(datas.get(position).getCategoryName());
        holder.selectAttrRv.setRv(datas.get(position));
    }


    public void setChecked(int checked) {
        this.checked = checked;
        notifyDataSetChanged();
    }

    //数据源的数量
    @Override
    public int getItemCount() {
        return datas.size();
    }

    class MyViewHolder extends RecyclerView.ViewHolder {
        private TextView categoryNameTv;
        private SelectAttrView selectAttrRv;


        public MyViewHolder(View itemView) {
            super(itemView);
            categoryNameTv = (TextView) itemView.findViewById(R.id.categoryNameTv);
            selectAttrRv = itemView.findViewById(R.id.selectAttrRv);

        }
    }
}

